package com.demo.messagebook.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jhello.core.annotations.web.At;
import com.jhello.core.annotations.web.Controller;
import com.jhello.core.model.Model;
import com.jhello.core.modelview.ModelAndView;
import com.jhello.core.view.JsonView;

@Controller
public class AjaxMessageBookController {


	@At("/ajaxlistdata2")
	public List<Map<String,Object>> ajaxList2(){
		return prepareListData();
	}
	
	@At("/ajaxlistdata")
	public ModelAndView ajaxList(){
		Model model = new Model();
		model.put("data", prepareListData());
		return new ModelAndView(new JsonView(), model);
	}
	
	@At("/ajaxlist")
	public String list(){
		return "view:ajaxlist.jsp";
	}
	
	private List<Map<String, Object>> prepareListData() {
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		for(int i = 0; i < 10; i ++){
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("id", "id"+i);
			map.put("message", "message1");
			list.add(map);
		}
		return list;
	}
}
